using Microsoft.Extensions.Configuration;

namespace sgf.server
{
    // 自定义 ConfigurationSource
    public class PropertyConfigurationSource : IConfigurationSource
    {
        public string filePath { get; init; }

        public IConfigurationProvider Build(IConfigurationBuilder builder)
        {
            return new PropertyConfigurationProvider { filePath = filePath };
        }
    }

// 自定义 ConfigurationProvider
    public class PropertyConfigurationProvider : ConfigurationProvider
    {
        public string filePath { get; init; }

        public override void Load()
        {
            // 读取并解析 .property 文件的逻辑
            // 请根据 .property 文件的实际格式进行解析
            var properties = new Dictionary<string, string>();
            foreach (var line in File.ReadLines(filePath))
            {
                var trimmedLine = line.Trim();
                if (string.IsNullOrEmpty(trimmedLine) ||
                    trimmedLine.StartsWith('#')) continue;
                var equalIndex = trimmedLine.IndexOf('=');
                if (equalIndex <= 0) continue;
                var key = trimmedLine[..equalIndex].Trim();
                var value = trimmedLine[(equalIndex + 1)..].Trim();
                properties[key] = value;
            }

            foreach (var kvp in properties)
            {
                Data.Add(kvp.Key, kvp.Value);
            }
        }
    }
}